<?php 
if(KT!='KhiThe') exit;
class newComments_model extends khithe_mysql{

	public function getcomments($page,$limit)
	{
		if($limit!=''){
			$page=($page==''?1:$page);
			$start = ($page - 1)* $limit; 
			$strlimit = "LIMIT $start, $limit";
		}
		else{
			$strlimit ='';
		}
		
		$select = "SELECT * FROM ".comments." WHERE NewsID <> 0 ORDER BY `ID` DESC ".$strlimit." ";
		$result = parent::SelectMySQL($select);
		parent::CloseConnection();
		return $result; 
	}
	
	public function getcommentID($ID){
		
		$ID = parent::checkStrMySQL($ID);
		$select = "SELECT * FROM ".comments." WHERE NewsID <> 0 AND ID = '".$ID."'";
		$result= parent::SelectMySQL($select);
		parent::CloseConnection();
		return $result;
	}
	
	public function setCheckedcomment($ID,$Val)
	{
		$ID = parent::checkStrMySQL($ID);
		$update = "UPDATE ".comments." SET Status='".$Val."'  WHERE NewsID <> 0 AND ID = '".$ID."'";
		parent::CloseConnection();
		return parent::UpdateInsertMySQL($update);
	}
	
	public function delCheckedcomment($ID)
	{
		$ID = parent::checkStrMySQL($ID);
		$del = "DELETE FROM ".comments." WHERE NewsID <> 0 AND ID='".$ID."' ";
		parent::CloseConnection();
		return parent::DeleteMySQL($del);
	}
}
?>